package com.ncloud.resman.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.resman.entity.CabinetUse;

@Mapper
public interface CabinetUseMapper{

	@Select("SELECT cabinet_id,device_id,use_num,state from res_cabinet_use where cabinet_id=#{0} ")
	@Results({
		@Result(column="cabinet_id",property="cabinetId"),@Result(column="device_id",property="deviceId"),
		@Result(column="use_num",property="useNum"),@Result(column="state",property="state")})
	List<CabinetUse> getCabinetUseById(Long cabinetId);

	@Insert(value = "INSERT INTO res_cabinet_use (cabinet_id, device_id,use_num,state) "
			+ "values(#{cabinetId},#{deviceId},#{useNum},#{state})")
    public int insertCabinetUse(CabinetUse cabinetUse);
	
	@Update(value = "UPDATE res_cabinet_use SET device_id = #{deviceId}, state = #{state} "
			+ "WHERE cabinet_id = #{cabinetId} and use_num = #{useNum}")
    public int updateCabinetUseById(CabinetUse cabinetUse);
	
	@Delete(value = "delete from res_cabinet_use WHERE cabinet_id = #{cabinetId}")
    public int deleteCabinetUse(Long cabinetId);
}
